package cn.labbook.bluetooth.service.impl;

import cn.labbook.bluetooth.entity.Admin;
import cn.labbook.bluetooth.mapper.AdminMapper;
import cn.labbook.bluetooth.service.IAdminService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lonzy
 * @since 2019-03-26
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements IAdminService {
    public  Admin login(String username, String password){
        LambdaQueryWrapper<Admin> lambda = new QueryWrapper<Admin>().lambda();
        lambda.eq(Admin::getAccountNumber, username)
                .eq(Admin::getPassword, password);
        return this.baseMapper.selectOne(lambda);
    }

    @Override
    public Admin getAdmin(String phone) {
        LambdaQueryWrapper<Admin> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Admin::getMobilephone, phone)
                .last("limit 1")
                .eq(Admin::getAdminStatus,2);
        return this.getOne(wrapper);
    }
}
